﻿using PLCS.Domain.Shared.Tasks;

namespace PLCS.Domain.Tasks;

public class HisTask : BaseEntity
{
    /// <summary>
    /// 任务号
    /// </summary>
    public int TaskId { get; init; }

    /// <summary>
    /// 上层任务号
    /// </summary>
    public string? TaskId_Higher { get; set; }

    /// <summary>
    /// 工单号
    /// </summary>
    public string? OrderNo { get; set; }

    /// <summary>
    /// 托盘号
    /// </summary>
    public string? TrayNo { get; set; }

    /// <summary>
    /// 任务来源
    /// </summary>
    public string TaskSource { get; set; }

    /// <summary>
    /// 任务类型
    /// </summary>
    public TaskType TaskType { get; set; }

    /// <summary>
    /// 任务起始位（大的目标）
    /// </summary>
    public string StartPos { get; set; }

    /// <summary>
    /// 任务目标位（大的目标）
    /// </summary>
    public string EndPos { get; set; }

    /// <summary>
    /// 任务级别
    /// </summary>
    public int Level { get; set; }

    /// <summary>
    /// 托盘类型
    /// </summary>
    public TrayType TrayType { get; set; }

    /// <summary>
    /// 任务状态
    /// </summary>
    public Shared.Tasks.TaskStatus TaskStatus { get; set; }

    /// <summary>
    /// 任务前执行方法
    /// </summary>
    public string? BeforeExecutionMethod { get; set; }

    /// <summary>
    /// 任务前执行参数
    /// </summary>
    public string? BeforeExecutionParam { get; set; }

    /// <summary>
    /// 任务完成执行方法
    /// </summary>
    public string? AfterExecutionMethod { get; set; }

    /// <summary>
    /// 任务完成执行参数
    /// </summary>
    public string? AfterExecutionParam { get; set; }

    /// <summary>
    /// 结束时间
    /// </summary>
    public DateTime FinshedTime { get; set; }

    /// <summary>
    /// 开始时间
    /// </summary>
    public DateTime? StartTime { get; set; }

    private HisTask()
    {
    }

    public HisTask(int taskId, int level, TrayType trayType, DateTime createTime, TaskType taskType, string taskSource, string startPos, string endPos, string? orderNo = null, string? beforeExecutionMethod = null, string? beforeExecutionParam = null, string? afterExecutionMethod = null, string? afterExecutionParam = null, string? taskId_Higher = null)
    {
        TaskId = taskId;
        Level = level;
        TrayType = trayType;
        TaskType = taskType;
        TaskSource = taskSource;
        OrderNo = orderNo;
        StartPos = startPos;
        CreationTime = createTime;
        EndPos = endPos;
        BeforeExecutionMethod = beforeExecutionMethod;
        AfterExecutionMethod = afterExecutionMethod;
        TaskStatus = Shared.Tasks.TaskStatus.已完成;
        FinshedTime = DateTime.Now;
        BeforeExecutionParam = beforeExecutionParam;
        AfterExecutionParam = afterExecutionParam;
        TaskId_Higher = taskId_Higher;
    }
}